﻿using SRB.Tg.Common;
using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class DrawingBridgeCatalog
    {

        BridgeStructureType bridge_type = BridgeStructureType.AviationBridge;
        System.Data.DataTable dtProject = new System.Data.DataTable();
        System.Data.DataTable dtBridge = new System.Data.DataTable();
        System.Data.DataTable dtBridgeDrawing = new System.Data.DataTable();
        System.Data.DataTable dtProjectConfig = new System.Data.DataTable();
        string _bridgeId = null;
        DrawingConfigModel drawingConfigModel = new DrawingConfigModel();
        public DrawingBridgeCatalog(string bridgeId, string categoryId,out System.Data.DataTable dtCategory, bool isMerge = false)
        {
            #region  参数数据初始化
            dtBridgeDrawing = new System.Data.DataTable();//图纸目录信息表
            //传入bridgeId，查询出mainId
            string sqlMainId = "select * from busi_bridge where id='" + bridgeId + "'";
            string mainId = MySqlHelper.ExecuteDataTable(sqlMainId, CommandType.Text).Rows[0]["main_id"].ToString();
            _bridgeId = mainId;
            string sqlBridge = "select * from busi_bridge_main where id='" + mainId + "'";
            dtBridge = MySqlHelper.ExecuteDataTable(sqlBridge, CommandType.Text);

            int bridge_scope = 1;//桥幅（单幅桥和双幅桥）
            if (dtBridge.Rows.Count > 0)
            {
                bridge_scope = int.Parse(dtBridge.Rows[0]["bridge_scope"].ToString());
                if (bridge_scope > 0)
                    isMerge = dtBridge.Rows[0]["drawing_level"].ToString() == "1" ? true : false; //双幅桥图纸是否合并
            }


            string sqlDrawing = "select * from busi_bridge_catalog where  (bridge_main_id='" + mainId + "' || bridge_id='"+ bridgeId + "' ) and id='" + categoryId + "'";
            dtBridgeDrawing = MySqlHelper.ExecuteDataTable(sqlDrawing, CommandType.Text);
            #endregion

            dtCategory = dtBridgeDrawing;
        }
        public void DrawingBridgeCatalogTable(Database db, int OverAllScale, string bridgeId, string categoryId, out System.Data.DataTable dtProjectConfigTb)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);

                string sql = "SELECT id,no,name,drawing_no,pages, remark"
                         + " FROM busi_bridge_catalog where bridge_id='" + bridgeId + "' and title<>'封面目录'  ORDER BY no asc";
                System.Data.DataTable dt = MySqlHelper.ExecuteDataTable(sql, CommandType.Text);


                List<string> list = new List<string>();
                list.Add("序号");
                list.Add("图件名称");
                list.Add("图号");
                list.Add("张数");
                list.Add("备注");
             

                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                OverAllScale = drawingConfigModel.drawing_scale;
                Extents2d Ext, ExtNote;
                Point2d RefPt, RefPtNote;
                RefPt = Point2d.Origin;
                Ext = new Extents2d();

                List<Extents2d> exfLst = new List<Extents2d>();
                RefPtNote = Point2d.Origin.C2D(); ;
                BridgeCatalogTable.DrawCatalogTable(db, ref exfLst, RefPtNote.C3D(), dt, list, Extensions.curFont, 1,  "目    录");
           


                ExtNote = new Extents2d();


                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateDefpointsLayout(db, "图纸", exfLst, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale, 1);
                Point2d tKPoint = Point2d.Origin;

                Extents2d ex = new Extents2d();
               // PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);

                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }
      
    }

    
}
